using System;
using System.Collections.Generic;
using System.Text;
using IGGCore;

namespace IGG
{
    public class ModeStandingsFormatter : IModeFormatter
    {
        #region IModeFormatter Members

        public void FormatMode(Scoreboard board)
        {
            if (board.StandingsNLE != null && board.StandingsNLE.Count > 0)
            {
                Output.WriteLine(" NL EAST             NL CENTRAL          NL WEST             NL WILCARD:");
                Output.Write(" ");
                FormatTeamStanding(board.StandingsNLE[0], false);
                FormatTeamStanding(board.StandingsNLC[0], false);
                FormatTeamStanding(board.StandingsNLW[0], false);
                FormatTeamStanding(board.StandingsNLWC[0], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsNLE[1], false);
                FormatTeamStanding(board.StandingsNLC[1], false);
                FormatTeamStanding(board.StandingsNLW[1], false);
                FormatTeamStanding(board.StandingsNLWC[1], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsNLE[2], false);
                FormatTeamStanding(board.StandingsNLC[2], false);
                FormatTeamStanding(board.StandingsNLW[2], false);
                FormatTeamStanding(board.StandingsNLWC[2], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsNLE[3], false);
                FormatTeamStanding(board.StandingsNLC[3], false);
                FormatTeamStanding(board.StandingsNLW[3], false);
                FormatTeamStanding(board.StandingsNLWC[3], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsNLE[4], false);
                FormatTeamStanding(board.StandingsNLC[4], false);
                FormatTeamStanding(board.StandingsNLW[4], false);
                FormatTeamStanding(board.StandingsNLWC[4], true);
                Output.Write(" ");
                FormatTeamStanding(null, false);
                FormatTeamStanding(board.StandingsNLC[5], false);
                FormatTeamStanding(null, false);
                FormatTeamStanding(board.StandingsNLWC[5], true);

                Output.WriteLine();
                Output.WriteLine(" AL EAST             AL CENTRAL          AL WEST             AL WILCARD");
                Output.Write(" ");
                FormatTeamStanding(board.StandingsALE[0], false);
                FormatTeamStanding(board.StandingsALC[0], false);
                FormatTeamStanding(board.StandingsALW[0], false);
                FormatTeamStanding(board.StandingsALWC[0], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsALE[1], false);
                FormatTeamStanding(board.StandingsALC[1], false);
                FormatTeamStanding(board.StandingsALW[1], false);
                FormatTeamStanding(board.StandingsALWC[1], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsALE[2], false);
                FormatTeamStanding(board.StandingsALC[2], false);
                FormatTeamStanding(board.StandingsALW[2], false);
                FormatTeamStanding(board.StandingsALWC[2], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsALE[3], false);
                FormatTeamStanding(board.StandingsALC[3], false);
                FormatTeamStanding(board.StandingsALW[3], false);
                FormatTeamStanding(board.StandingsALWC[3], true);
                Output.Write(" ");
                FormatTeamStanding(board.StandingsALE[4], false);
                FormatTeamStanding(board.StandingsALC[4], false);
                FormatTeamStanding(null, false);
                FormatTeamStanding(board.StandingsALWC[4], true);
            }
            else
            {
                // spring!
                Output.WriteLine(" GRAPEFRUIT                      CACTUS          ");
                for (int i = 0; i < 15; i++)
                {
                    Output.Write(" ");
                    FormatTeamStanding(board.StandingsGrapefruit[i], false);
                    FormatTeamStanding(board.StandingsCactus[i], true);
                }
            }
        }

        private void FormatTeamStanding(StandingTeam team, bool end)
        {
            if (team != null)
            {
                if (team.code != null && team.code.Trim() != "")
                {
                    Output.Write(ToolBox.GetFormattedStringPadRight(team.code, 5));
                }
                else
                {
                    Output.Write(ToolBox.GetFormattedStringPadRight(team.team, 17));
                }

                Output.Write(ToolBox.GetFormattedStringPadRight(team.w.ToString(), 4));
                Output.Write(ToolBox.GetFormattedStringPadRight(team.l.ToString(), 4));
                if (end)
                {
                    Output.WriteLine(team.gb.ToString());
                }
                else
                {
                    Output.Write(ToolBox.GetFormattedStringPadRight(team.gb.ToString(), 7));
                }
            }
            else
            {
                if (end)
                {
                    Output.WriteLine();
                }
                else
                {
                    Output.Write(ToolBox.GetFormattedStringPadRight(" ", 20));
                }
            }
        }


        #endregion
    }
}
